package com.newtest.demos.mapper;

import com.newtest.demos.pojo.LoginUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface LoginMapper {

    //根据用户名或密码查询
    @Select("select * from user_login where username = #{username} and password = #{password}")
    LoginUser getByUsernameAndPassword(LoginUser loginUser);

    @Insert("INSERT INTO user_login (username, password,email) VALUES (#{username}, #{password},#{email})")
    void insertUser(LoginUser loginUser);

    @Update("UPDATE user_login SET password = #{password} WHERE username = #{username};")
    int updateUser(LoginUser loginUser);

    @Delete("delete from user_login where username = #{username}")
    int deleteUser(LoginUser loginUser);

    // 根据用户名检查用户是否存在
    @Select("SELECT COUNT(*) FROM user_login WHERE username = #{username}")
    int isUsernameExists(@Param("username") String username);

    // 根据邮箱检查用户是否存在
    @Select("SELECT COUNT(*) FROM user_login WHERE email = #{email}")
    int isEmailExists(@Param("email") String email);

    //查询个人信息
    @Select("SELECT id,username,email FROM user_login WHERE username = #{username}")
    List<LoginUser> findAllUser(@Param("username") String username);
}
